<template>
  <div class="bg-[#232324] h-[100%]">
    <el-collapse v-loading="loading" v-model="activeNames">
      <el-form label-width="100" :model="states" size="default">
        <template v-for="(item, i) in states" :key="i + 'a'">
          <el-collapse-item
            :title="`折线图`"
            :name="i + 1"
            v-if="item.type === 'line'"
          >
            <el-form-item label="线条宽度">
              <el-input-number v-model="item.lineStyle.width" />
            </el-form-item>
            <el-form-item label="线条颜色">
              <el-color-picker v-model="item.lineStyle.color" />
            </el-form-item>
            <el-form-item label="线条类型">
              <el-select v-model="item.lineStyle.type" placeholder="Select">
                <el-option label="实线" value="solid" />
                <el-option label="虚线" value="dashed" />
                <el-option label="点线" value="dotted" />
              </el-select>
            </el-form-item>
            <el-form-item label="填充颜色">
              <el-color-picker v-model="item.areaStyle.color" />
            </el-form-item>
            <el-form-item label="填充透明度">
              <el-input-number
                v-model="item.areaStyle.opacity"
                :step="0.1"
                :min="0"
                :max="1"
              />
            </el-form-item>
            <el-form-item label="取消高亮">
              <el-switch v-model="item.emphasis.disabled" />
            </el-form-item>
            <el-form-item label="高亮选项">
              <el-select v-model="item.emphasis.focus" placeholder="Select">
                <el-option label="聚焦系列所有图形" value="series" />
                <el-option label="聚焦当前数据图形" value="self" />
                <el-option label="不淡出其它图形" value="none" />
              </el-select>
            </el-form-item>
            <el-form-item label="标记类型">
              <el-select v-model="item.symbol" placeholder="Select">
                <el-option label="圆形" value="circle" />
                <el-option label="方形" value="rect" />
                <el-option label="圆角方形" value="roundRect" />
                <el-option label="三角形" value="triangle" />
                <el-option label="菱形" value="diamond" />
                <el-option label="倒三角形" value="pin" />
                <el-option label="箭头" value="arrow" />
                <el-option label="无" value="none" />
              </el-select>
            </el-form-item>
            <el-form-item label="标记大小">
              <el-input-number v-model="item.symbolSize" />
            </el-form-item>
            <el-form-item label="标签文字">
              <el-switch v-model="item.label.show" />
            </el-form-item>
            <el-form-item label="标签文字大小">
              <el-input-number v-model="item.label.fontSize" />
            </el-form-item>
            <el-form-item label="标签文字颜色">
              <el-color-picker v-model="item.label.color" />
            </el-form-item>
            <el-form-item label="标签文字位置">
              <el-select v-model="item.label.position" placeholder="Select">
                <el-option label="top" value="top" />
                <el-option label="left" value="left" />
                <el-option label="right" value="right" />
                <el-option label="bottom" value="bottom" />
              </el-select>
            </el-form-item>
          </el-collapse-item>
        </template>
        <template v-for="(item, i) in states" :key="i + 'a'">
          <el-collapse-item
            :title="`柱状图`"
            :name="i + 1"
            v-if="item.type === 'bar'"
          >
            <el-form-item label="柱宽度">
              <el-input v-model="item.barWidth" />
            </el-form-item>
            <el-form-item label="柱颜色">
              <el-color-picker v-model="item.itemStyle.color" />
            </el-form-item>
            <el-form-item label="柱圆角">
              <el-input-number v-model="item.itemStyle.borderRadius" :min="0" />
            </el-form-item>
            <el-form-item label="柱透明度">
              <el-input-number
                v-model="item.itemStyle.opacity"
                :step="0.1"
                :min="0"
                :max="1"
              />
            </el-form-item>
            <el-form-item label="柱背景">
              <el-switch v-model="item.showBackground" />
            </el-form-item>
            <el-form-item label="取消高亮">
              <el-switch v-model="item.emphasis.disabled" />
            </el-form-item>
            <el-form-item label="高亮选项">
              <el-select v-model="item.emphasis.focus" placeholder="Select">
                <el-option label="聚焦系列所有图形" value="series" />
                <el-option label="聚焦当前数据图形" value="self" />
                <el-option label="不淡出其它图形" value="none" />
              </el-select>
            </el-form-item>
            <el-form-item label="柱背景">
              <el-switch v-model="item.showBackground" />
            </el-form-item>
            <el-form-item label="背景色">
              <el-color-picker v-model="item.backgroundStyle.color" />
            </el-form-item>
            <el-form-item label="背景圆角">
              <el-input-number
                v-model="item.backgroundStyle.borderRadius"
                :min="0"
              />
            </el-form-item>
            <el-form-item label="背景透明度">
              <el-input-number
                v-model="item.backgroundStyle.opacity"
                :step="0.1"
                :min="0"
                :max="1"
              />
            </el-form-item>
            <el-form-item label="标签文字">
              <el-switch v-model="item.label.show" />
            </el-form-item>
            <el-form-item label="标签文字大小">
              <el-input-number v-model="item.label.fontSize" />
            </el-form-item>
            <el-form-item label="标签文字颜色">
              <el-color-picker v-model="item.label.color" />
            </el-form-item>
            <el-form-item label="标签文字位置">
              <el-select v-model="item.label.position" placeholder="Select">
                <el-option label="top" value="top" />
                <el-option label="left" value="left" />
                <el-option label="right" value="right" />
                <el-option label="bottom" value="bottom" />
              </el-select>
            </el-form-item>
          </el-collapse-item>
        </template>
      </el-form>
    </el-collapse>
  </div>
</template>

<script setup>
import { computed, onMounted, watch, ref } from "vue";
const loading = ref(true);
const activeNames = ref();
const props = defineProps({
  models: {
    type: Object,
    default: () => ({}),
  },
});
const emit = defineEmits(["update:models", "edit"]);
let states = ref(null);
onMounted(() => {
  setTimeout(() => {
    loading.value = false;
  }, 200);

  states.value = JSON.parse(JSON.stringify(props.models.series));
});

watch(
  () => states.value,
  (val) => {
    emit("update:models", { ...props.models, series: val });
  },
  {
    deep: true,
  }
);
</script>

<style scoped lang="scss">
:deep(.el-collapse-item__header) {
  padding-left: 10px !important;
}

:deep(.el-input) {
  width: 180px !important;
}
:deep(.el-select) {
  width: 180px !important;
}
</style>
